package com.code.petapp.util;

import android.util.Log;

import com.code.petapp.http.HttpApiService;
import com.code.petapp.http.HttpListener;
import com.code.petapp.http.RetrofitHelper;
import com.code.petapp.http.RxObserver;

import okhttp3.MultipartBody;

public class UploadUtils {
    public static void upload(String token, MultipartBody.Part filePart, HttpListener<String> httpListener){
        Log.d("Tag","upload start");
        new RetrofitHelper().createApi(HttpApiService.class)
                .upLoadFile(token,filePart)
                .compose(RetrofitHelper.schedulersTransformer())
                .subscribe(new RxObserver<>() {
                    @Override
                    public void success(String path) {
                        Log.d("UploadUtils", "成功接收到数据: " + path);
                        httpListener.success(path);
                    }

                    @Override
                    public void error(int code, String error) {
                        httpListener.error(code,error);
                    }
                });
    }
}
